#!/bin/sh
set -e

. /usr/libexec/os-helpers-logging
. /usr/libexec/os-helpers-config

if [ -f "${CONFIG_PATH}" ]; then
	development_mode="$(jq -r ".developmentMode" "${CONFIG_PATH}")"
	if [ "${development_mode}" = "true" ]; then
		config_gen_devmode
		info "Entering development mode"
		/bin/systemctl restart development-features.target
	else
		if [ -f "${DEVELOPMENT_FEATURES_FLAG_FILE}" ]; then
			rm -rf "${DEVELOPMENT_FEATURES_FLAG_FILE}"
			info "Entering production mode"
			/bin/systemctl restart development-features.target
		fi
	fi
fi
